package com.lagou.dao.impl;

import com.lagou.dao.ArticleDao;
import com.lagou.domain.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class AccountDaoImpl implements ArticleDao {


    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Article> findAll() {
        String sql = "select * from t_article";

        List<Article> articleList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Article.class));

        return articleList;
    }

    @Override
    public void saveArticle(Article article) {

        String sql = "insert into t_article values(null,?,?)";

        jdbcTemplate.update(sql,article.getTitle(),article.getContent());
    }
}
